import sys
from PyQt6.QtWidgets import QApplication, QWidget, QVBoxLayout, QListWidget
from PyQt6.QtCore import QDir

class FileListWidget(QWidget):
    def __init__(self, folder_path):
        super().__init__()
        self.initUI(folder_path)

    def initUI(self, folder_path):
        layout = QVBoxLayout()
        self.listWidget = QListWidget()

        # 使用 QDir 获取指定文件夹中的文件
        dir = QDir(folder_path)
        file_info_list = dir.entryInfoList(QDir.Filter.AllEntries | QDir.Filter.NoDotAndDotDot)

        for file_info in file_info_list:
            self.listWidget.addItem(file_info.fileName())

        layout.addWidget(self.listWidget)
        self.setLayout(layout)

        self.setGeometry(300, 300, 350, 250)
        self.setWindowTitle('指定文件夹文件列表')
        self.show()

if __name__ == '__main__':
    app = QApplication(sys.argv)
    folder_path = "your_specified_folder_path"  # 请将此处替换为您实际的指定文件夹路径
    ex = FileListWidget(folder_path)
    sys.exit(app.exec())